package cn.wolfcode.web.controller;


import cn.wolfcode.domain.ActivityItem;
import cn.wolfcode.service.IActivityItemService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
@RequestMapping("/activityItem")
public class ActivityItemController {

    @Autowired
    private IActivityItemService activityItemService;


    @RequiredPermission(name="投票明细页面",expression="activityItem:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<ActivityItem> pageInfo = activityItemService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "activityItem/list";
    }


    @RequiredPermission(name="投票明细删除",expression="activityItem:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           activityItemService.delete(id);
        }
        return "redirect:/activityItem/list";
    }



    @RequiredPermission(name="投票明细新增/编辑",expression="activityItem:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("activityItem",activityItemService.get(id));
        }
        return "activityItem/input";
    }
}
